﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoneyWentWhere.DataModel.Reports
{
    public class TableReportColumn : IComparable
    {
        // Key with some elements filtered out -- date at the very least
        public readonly PeriodAmountKey Key;

        public TableReportColumn(Account acct, TransactionKind kind, bool isDeposit, String category)
        {
            Key = new PeriodAmountKey(
                DateTime.MinValue, // Always the same
                TimeSpanUnit.Day,  // Arbitrary, always the same
                acct, kind, isDeposit, category);
        }

        public String Name
        {
            get
            {
                return String.Format("{0}/{1} {2} {3}{4}",
                    Key.Account.Name,
                    Key.Account.Currency,
                    Key.Kind,
                    Key.Category,
                    Key.IsDeposit ? "+" : "-");
            }
        }

        public override string ToString()
        {
            return Name;
        }

        public override int GetHashCode()
        {
            return Key.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            TableReportColumn that = obj as TableReportColumn;
            if (that == null) { return false; }
            return Key.Equals(that.Key);
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            TableReportColumn that = obj as TableReportColumn;
            if (that == null) { return -1; }
            return Key.CompareTo(that.Key);
        }

        #endregion
    }
}
